package com.biz.hunter.dao;

import java.util.List;

import com.biz.hunter.db.entity.SchJob;
import com.biz.hunter.dbutil.BaseDAO;
import org.springframework.stereotype.Repository;


@Repository
public class SchJobDAO {
	
	
	private final static String SQL_INSERT = "insert sch_job (id,name,description,specialty,degree,talentSource"
			+ ",graduateDate,returnee,createTime,updateTime,createBy,cityId) values (?,?,?,?,?,?,?,?,NOW(),NOW(),?,?)";
	public void insert(SchJob schjob) {
		// TODO Auto-generated method stub
		BaseDAO.execute(SQL_INSERT, schjob.getId(),schjob.getName(),schjob.getDescription(),schjob.getSpecialty()
				,schjob.getDegree(),schjob.getTalentSource(),schjob.getGraduateDate(),schjob.getReturnee(),schjob.getCreateBy(),schjob.getCityId());
	}

	private final static String SQL_GET = "select * from sch_job where id = ?"; 
	public SchJob getById(String id) {
		// TODO Auto-generated method stub
		return BaseDAO.queryForObject(SchJob.class, SQL_GET, id);
	}

	private final static String SQL_UPDATE = "update sch_job set name = ?, description = ?, specialty = ?, degree = ?,"
			+ "talentSource = ?, graduateDate = ?, returnee = ?,updateTime = now(),cityId=? where id = ?";
	public void update(SchJob schjob) {
		// TODO Auto-generated method stub
		BaseDAO.execute(SQL_UPDATE, schjob.getName(),schjob.getDescription(),schjob.getSpecialty(),schjob.getDegree(),
				schjob.getTalentSource(),schjob.getGraduateDate(),schjob.getReturnee(),schjob.getCityId(),schjob.getId());
	}

	private final static String SQL_DELETE = "delete from sch_job where id = ?"; 
	public int delete(String id) {
		// TODO Auto-generated method stub
		return BaseDAO.execute(SQL_DELETE, id);
	}
	
	private final static String SQL_COUNT = "select count(1) from sch_job where createBy = ?";
	public int count(SchJob schjob) {
		// TODO Auto-generated method stub
		return BaseDAO.execute(SQL_COUNT, schjob.getCreateBy());
	}
	
	private final static String SQL_PAGE = "select * from sch_job where createBy = ?";
	public List<SchJob> page(SchJob schjob, Integer offset, Integer size) {
		// TODO Auto-generated method stub
		String sql = SQL_PAGE + " order by updateTime desc limit ?,?";
		return BaseDAO.queryForList(SchJob.class, sql, schjob.getCreateBy(), offset, size);
	}

}
